home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-09-14 | 1.9 KB | 81 lines | [TEXT/MPS ] |
- //
- // MPW Tool by im.
- // Usage : TCPReceive
- //
-
- #include <QuickDraw.h>
- #include <Devices.h>
- #include <stdio.h>
-
- #include <MacTCPCommonTypes.h>>
- #include <AddressXlation.h>
- #include <GetMyIPAddr.h>
- #include <TCPPB.h>
- #include <UDPPB.h>
-
- #define _STORAGE_ true
- #include <TCP.h>
-
-
- main (int argc, char *argv[], char *envp[]) {
-
- auto OSErr osErr = noErr;
- auto short index;
- auto char *option;
- auto char *parameter;
- auto TCPNotifyProc asrProc = nil;
- auto TCPiopb pb;
- auto StreamPtr stream;
- auto char streamBuf[4096];
- auto long streamBufLen = sizeof(streamBuf);
- auto Ptr streamBufPtr;
- auto char ioBuf[256] = "";
- auto unsigned short ioBufLen = sizeof(ioBuf);
- auto ip_addr localIP = cAnyIP;
- auto ip_port localPort = cReceivePort;
- auto ip_addr remoteIP = cAnyIP;
- auto ip_port remotePort = cAnyPort;
-
- InitGraf((Ptr) &qd.thePort);
-
- index = 1;
- while (index < argc) {
-
- option = argv[index++];
- //parameter = argv[index++];
-
- if ('-' != option[0] || (! strchr("n", option[1])) || index > argc) {
- printf("TCPReceive [-n]");
- exit(1);
- } else {
- switch (option[1]) {
- case 'n' :
- asrProc = ASR;
- //index--;
- break;
- }
- }
- }
-
- osErr = _TCPInit();
- if (noErr == osErr) {
- osErr = _TCPCreate(&pb, &stream, streamBuf, streamBufLen, (TCPNotifyProc) asrProc, (Ptr) nil, (TCPIOCompletionProc) nil, false);
- if (noErr == osErr) {
- osErr = _TCPPassiveOpen(&pb, stream, &remoteIP, &remotePort, &localIP, &localPort, (Ptr) nil, (TCPIOCompletionProc) nil, false);
- if (noErr == osErr) {
-
- /* receive data from the remote host */
- osErr = _TCPRcv(&pb, stream, ioBuf, &ioBufLen, (Ptr) nil, (TCPIOCompletionProc) nil, false);
- if (noErr == osErr)
- printf("%s\n", ioBuf);
-
- osErr = _TCPClose(&pb, stream, nil, (TCPIOCompletionProc) nil, false);
- }
- osErr = _TCPRelease(&pb, stream, &streamBufPtr, &streamBufLen, (TCPIOCompletionProc) nil, false);
- }
- }
-
- exit(osErr);
- }
-
-